package mini.expr;

import java.util.HashMap;

public class Expr {

	// All temp counters are unique so make it static
	public static int tempCounter = 0;
	
	// Where this expression stores its result
	private String tempVariable;
    
	// All expressions will get a temp variable of their very own
    public Expr(){
    	setTempVariable( nextTempVariable() );
    }
    
    // This should be overwritten
    public Integer eval(HashMap hm){
    	return new Integer(0);
    }
    
    // This should be overwritten, so spit out an error code if it's not
    public String parse(HashMap hm) {
    	return "ILL";
    }
    
	public String getTempVariable() {
		return tempVariable;
	}
	
	public void setTempVariable( String temp ) {
		tempVariable = temp;
	}
    
	/**
	 * Generates the unique name for a temp variable.
	 * NOTE: Though it probably won't break things, if
	 * you the developer change how temp variables are
	 * formed, in terms of their name, please modify the
	 * Linker.java class and, in particular, the
	 * isTempVariable() and isUserVariable() methods,
	 * accordingly!
	 * @return
	 */
    public String nextTempVariable() {
    	String var = "temp" + tempCounter;
    	tempCounter++;
    	return var;
    }

	@Override
	public String toString() {
		return "Expr [tempVariable=" + tempVariable + "]";
	}
}
